﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using  ManagerServices.Entity;
using ManagerServices.Data;
using System.Data.Common;
using System.Data;
using ManagerServices.Constants;

namespace ManagerServices.Controller
{
    public class UserProfileController
    {
        private int  resultsAccount = 0;

        public int CreateAccount(UserEntity userinfo , ProfileEntity profileinfo)
        {
            int idprofile = 0;
            bool bvalidateMail = false; 

            try
            {
                //validar si el correo existe
                bvalidateMail = UserData.Instance.ValidationMail(userinfo.MAIL);

                if (bvalidateMail == false)
                {

                    idprofile = ProfileData.Instance.Createprofile(profileinfo);

                    if (idprofile > 0)
                    {
                        //Obtener el id del perfil
                        //ProfileData.Instance.GetProfile()
                        userinfo.ID_PROFILE = idprofile;
                        UserData.Instance.CreateUser(userinfo);

                    }
                    else 
                    {
                        //No ha podido crear la cuenta de usuario pero si el perfil
                        resultsAccount = (int)UserResults.ErrorCreateUser;
                      

                    }
                }
                else {

                    //La cuenta ya existe
                    resultsAccount = (int)UserResults.Notexist;
                    
                }

                
            }
            catch  {

                //Error exception mirar controller
                resultsAccount = (int)UserResults.ErrorException;
            }

            return resultsAccount;  
        }

    }
}